package ink.zhaohui.javaStudy.processor;

import java.util.Iterator;
import java.util.Set;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;

@SupportedAnnotationTypes({ "ink.zhaohui.javaStudy.annotation.Monitor" })
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class MonitorProcessor extends AbstractProcessor {

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        System.out.println("begin----------------");
        printTypeElement(annotations);
        System.out.println("end------------------");

        System.out.println("begin----------------");
        printRoundEnvironment(roundEnv);
        System.out.println("end------------------");
        return false;
    }

    private void printTypeElement(Set<? extends TypeElement> annotations) {
        Iterator it = annotations.iterator();
        while (it.hasNext()) {
            System.out.println("TypeElement[" + it.next() + "]");
        }
    }

    private void printRoundEnvironment(RoundEnvironment roundEnv) {
        Iterator it = roundEnv.getRootElements().iterator();
        while (it.hasNext()) {
            System.out.println("RoundEnvironment[" + it.next() + "]");
        }
    }

}